import { defineStore } from 'pinia'
import { dataGet, qualityGet } from '../../api/realTime/realTimeData'
import { log } from 'console'
interface dataListType {
    address: string,
    pressure: number,
    temperature: number,
    electricQuantity: number,
    pressureY: number,
    updateTime: string,
    addressId: string,
    attention: number,
    instantFlow: number,
    totalFlow: number,
    cloudyDegree: number,
    surplusOxygen: number,
    PH: number,
    alarmRangeA: number,
    alarmRangeB: number,
    alarmRangeC: number
}

interface stateStyle {
    dataList: Array<dataListType>
    realTimeList: Array<dataListType>
    realTimeListB: Array<dataListType>
}



export const userRealTimeData = defineStore('alerts', {
    state: () => <stateStyle>({
        dataList: [],
        stated: null,
        realTimeList: [
            {
                "address": "高新科技园南",
                "pressure": 0.23,
                "temperature": 20,
                "electricQuantity": 90,
                "pressureY": 0.25,
                "updateTime": "10:15",
                "addressId": "city111",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 2,
                "alarmRangeC": 1
            },
            {
                "address": "大冲花园",
                "pressure": 0.26,
                "temperature": 21,
                "electricQuantity": 92,
                "pressureY": 0.21,
                "updateTime": "10:15",
                "addressId": "city112",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "梅林一村",
                "pressure": 0.20,
                "temperature": 22,
                "electricQuantity": 88,
                "pressureY": 0.19,
                "updateTime": "10:15",
                "addressId": "city113",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 2,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "四季山水",
                "pressure": 0.23,
                "temperature": 20,
                "electricQuantity": 92,
                "pressureY": 0.21,
                "updateTime": "10:15",
                "addressId": "city114",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 2,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "安全中心",
                "pressure": 0.30,
                "temperature": 21,
                "electricQuantity": 90,
                "pressureY": 0.25,
                "updateTime": "10:15",
                "addressId": "city115",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 2,
                "alarmRangeC": 3
            },
            {
                "address": "蒙德",
                "pressure": 0.23,
                "temperature": 18,
                "electricQuantity": 93,
                "pressureY": 0.22,
                "updateTime": "10:15",
                "addressId": "city116",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 3,
                "alarmRangeB": 3,
                "alarmRangeC": 3
            },
            {
                "address": "稻妻",
                "pressure": 0.32,
                "temperature": 20,
                "electricQuantity": 90,
                "pressureY": 0.25,
                "updateTime": "10:15",
                "addressId": "city117",
                "attention": 2,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 3,
                "alarmRangeC": 1
            },
            {
                "address": "璃岳",
                "pressure": 0.27,
                "temperature": 22,
                "electricQuantity": 90,
                "pressureY": 0.21,
                "updateTime": "10:15",
                "addressId": "city118",
                "attention": 2,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "须弥",
                "pressure": 0.23,
                "temperature": 22,
                "electricQuantity": 91,
                "pressureY": 0.19,
                "updateTime": "10:15",
                "addressId": "city119",
                "attention": 2,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "枫丹",
                "pressure": 0.23,
                "temperature": 20,
                "electricQuantity": 92,
                "pressureY": 0.28,
                "updateTime": "10:15",
                "addressId": "city121",
                "attention": 2,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 2,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "三台山",
                "pressure": 0.26,
                "temperature": 20,
                "electricQuantity": 92,
                "pressureY": 0.28,
                "updateTime": "10:15",
                "addressId": "city122",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "红十字中心",
                "pressure": 0.27,
                "temperature": 20,
                "electricQuantity": 92,
                "pressureY": 0.28,
                "updateTime": "10:15",
                "addressId": "city123",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 3
            },
            {
                "address": "南沟",
                "pressure": 0.23,
                "temperature": 21,
                "electricQuantity": 92,
                "pressureY": 0.28,
                "updateTime": "10:15",
                "addressId": "city124",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            }
        ],
        realTimeListB: [
            {
                "address": "高新科技园南",
                "pressure": 0.23,
                "temperature": 20,
                "electricQuantity": 90,
                "pressureY": 0.25,
                "updateTime": "10:15",
                "addressId": "city111",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 2,
                "alarmRangeC": 1
            },
            {
                "address": "大冲花园",
                "pressure": 0.26,
                "temperature": 21,
                "electricQuantity": 92,
                "pressureY": 0.21,
                "updateTime": "10:15",
                "addressId": "city112",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "梅林一村",
                "pressure": 0.20,
                "temperature": 22,
                "electricQuantity": 88,
                "pressureY": 0.19,
                "updateTime": "10:15",
                "addressId": "city113",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 2,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "四季山水",
                "pressure": 0.23,
                "temperature": 20,
                "electricQuantity": 92,
                "pressureY": 0.21,
                "updateTime": "10:15",
                "addressId": "city114",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 2,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "安全中心",
                "pressure": 0.30,
                "temperature": 21,
                "electricQuantity": 90,
                "pressureY": 0.25,
                "updateTime": "10:15",
                "addressId": "city115",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 2,
                "alarmRangeC": 3
            },
            {
                "address": "蒙德",
                "pressure": 0.23,
                "temperature": 18,
                "electricQuantity": 93,
                "pressureY": 0.22,
                "updateTime": "10:15",
                "addressId": "city116",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 3,
                "alarmRangeB": 3,
                "alarmRangeC": 3
            },
            {
                "address": "稻妻",
                "pressure": 0.32,
                "temperature": 20,
                "electricQuantity": 90,
                "pressureY": 0.25,
                "updateTime": "10:15",
                "addressId": "city117",
                "attention": 2,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 3,
                "alarmRangeC": 1
            },
            {
                "address": "璃岳",
                "pressure": 0.27,
                "temperature": 22,
                "electricQuantity": 90,
                "pressureY": 0.21,
                "updateTime": "10:15",
                "addressId": "city118",
                "attention": 2,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "须弥",
                "pressure": 0.23,
                "temperature": 22,
                "electricQuantity": 91,
                "pressureY": 0.19,
                "updateTime": "10:15",
                "addressId": "city119",
                "attention": 2,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "枫丹",
                "pressure": 0.23,
                "temperature": 20,
                "electricQuantity": 92,
                "pressureY": 0.28,
                "updateTime": "10:15",
                "addressId": "city121",
                "attention": 2,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 2,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "三台山",
                "pressure": 0.26,
                "temperature": 20,
                "electricQuantity": 92,
                "pressureY": 0.28,
                "updateTime": "10:15",
                "addressId": "city122",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            },
            {
                "address": "红十字中心",
                "pressure": 0.27,
                "temperature": 20,
                "electricQuantity": 92,
                "pressureY": 0.28,
                "updateTime": "10:15",
                "addressId": "city123",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 3
            },
            {
                "address": "南沟",
                "pressure": 0.23,
                "temperature": 21,
                "electricQuantity": 92,
                "pressureY": 0.28,
                "updateTime": "10:15",
                "addressId": "city124",
                "attention": 1,
                "instantFlow": 222.168,
                "totalFlow": 168257.114,
                "cloudyDegree": 0.31,
                "surplusOxygen": 0.15,
                "PH": 7.45,
                "alarmRangeA": 1,
                "alarmRangeB": 1,
                "alarmRangeC": 1
            }
        ]
    }),
    // 获取水压数据的函数
    actions: {
        async dataInit(where: Array<number>) {
            // let res = await dataGet(where)
            // this.dataList = res.data.results
            this.realTimeList = []
            for (let i = 0; i < this.realTimeListB.length; i++) {
                if (where[0] == 100) {
                    if (this.realTimeListB[i].attention == 2) {
                        this.realTimeList.push(this.realTimeListB[i])
                    }
                } else {
                    if (this.realTimeListB[i].pressure < where[1] && where[0] <= this.realTimeListB[i].pressure) {
                        this.realTimeList.push(this.realTimeListB[i])
                    }
                }

            }
            // console.log(this.dataList);

        },
        async flowInit(where: Array<number>) {
            let res = await dataGet(where)
            this.dataList = res.data.results
            // console.log(this.dataList);

        },
        async qualityInit(where: Array<number>) {
            let res = await dataGet(where)
            this.dataList = res.data.results
            // console.log(this.dataList);

        },
        chnageRealTimeList() {
            let num = 0
            for (let i = 0; i < this.realTimeList.length; i++) {
                num = Math.floor(Math.random() * 10 + 1)
                if (num <= 3) {
                    this.realTimeList[i].pressure += 0.01
                } else if (num <= 6) {
                    this.realTimeList[i].pressure += 0.00
                } else {
                    this.realTimeList[i].pressure -= 0.01
                }
            }
        }
    }
})
